package com.zmn.uac.api.controllers;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.uac.client.CaptchaClient;
import com.zmn.uuc.common.constant.CaptchaConsts;
import com.zmn.uuc.common.dio.captcha.ValidateCaptchaDIO;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * 类描述：基础控制器
 *
 * @author xujie
 * @since 2021/06/15 11:36
 */
@Slf4j
public class BaseController {

    private static final String TAG = "基础控制器";

    @Resource
    CaptchaClient captchaClient;

    /**
     * 校验验证码
     *
     * @param plat    平台
     * @param mobile  手机号码
     * @param captcha 验证码
     * @return ResponseDTO<Boolean>
     * @author xujie
     * @since 2021/06/14
     */
    protected ResponseDTO<Boolean> validateCaptcha(Integer plat, String mobile, String captcha) {

        // 校验验证码
        ValidateCaptchaDIO validateCaptcha = new ValidateCaptchaDIO();
        validateCaptcha.setPlat(plat);
        validateCaptcha.setMobile(mobile);
        validateCaptcha.setType(CaptchaConsts.CAPTCHA_TYPE_USER_REGISTER_LOGIN);
        validateCaptcha.setCaptcha(captcha);

        Boolean validateStatus = captchaClient.validateCaptcha(validateCaptcha);

        return new ResponseDTO<>(validateStatus);
    }

    /**
     * 校验验证码
     *
     * @param plat    平台
     * @param mobile  手机号码
     * @param captcha 验证码
     * @param type    验证码类型
     * @return
     */
    protected ResponseDTO<Boolean> validateCaptcha(Integer plat, String mobile, String captcha, Integer type) {
        ValidateCaptchaDIO validateCaptcha = new ValidateCaptchaDIO();
        validateCaptcha.setPlat(plat);
        validateCaptcha.setMobile(mobile);
        validateCaptcha.setType(type);
        validateCaptcha.setCaptcha(captcha);

        Boolean validateStatus = captchaClient.validateCaptcha(validateCaptcha);

        return new ResponseDTO<>(validateStatus);
    }
}
